﻿using System;
using System.Windows.Forms;

namespace Texpro
{
    public partial class FMMN104 : Form
    {
        int zoom_scale = 2;

        public FMMN104()
        {
            InitializeComponent();
        }

        private void frm_report_viewer_Load(object sender, EventArgs e)
        {
            open_report();
            zoom_scale = 2;
            zoom_report(zoom_scale);
        }

        private void open_report()
        {
            int i = 0;
            int dc = 0;
            CrystalDecisions.Shared.PageMargins pm;
            String rep_org_name = String.Empty;
            String rep_org_address = String.Empty;
            UseWaitCursor = true;
            try
            {
                rep_org_name = PCPUB.mc_org_name.ToString();
                rep_org_address = PCPUB.mc_org_address1.ToString();
                rep_org_address += ", " + PCPUB.mc_org_address2.ToString();
                rep_org_address += ", " + PCPUB.mc_org_address3.ToString();
                rep_org_address += ", " + PCPUB.mc_org_city.ToString();
                rep_org_address += ". Pin:" + PCPUB.mc_org_pincode.ToString();
                rep_org_address += "  Phone:" + PCPUB.mc_org_phone1.ToString();
                pm.leftMargin = 500;
                pm.rightMargin = 500;
                pm.topMargin = 500;
                pm.bottomMargin = 500;
                rd1.FileName = PCREP.m_local_report_path + PCREP.m_local_report_file;
                rd1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA5;
                rd1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
                rd1.PrintOptions.ApplyPageMargins(pm);
                //
                //PCMSG.Show(rd1.PrintOptions.PaperSize.ToString());
                //rd1.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)System.Drawing.Printing.PaperKind.A5Rotated;
                //PCMSG.Show(rd1.PrintOptions.PaperSize.ToString());
                //// Add list of supported paper sizes found on the printer.  
                //// The DisplayMember property is used to identify the property that will provide the display string.
                //comboPaperSize.DisplayMember = "PaperName";
                //
                //PaperSize pkSize;
                //for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
                //    pkSize = printDoc.PrinterSettings.PaperSizes[i];
                //    comboPaperSize.Items.Add(pkSize);
                //}
                //// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
                //PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);
                //comboPaperSize.Items.Add(pkCustomSize1);
                //
                switch (this.Tag.ToString())
                {
                    case "RPTR101":
                        lbl_form_title.Text = "Print Yarn Purchase Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR111":
                        lbl_form_title.Text = "Print Yarn Sales Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR121":
                        lbl_form_title.Text = "Print Yarn Material Inward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR201":
                        lbl_form_title.Text = "Print Dyeing Outward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR211":
                        lbl_form_title.Text = "Print Dyeing Inward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR301":
                        lbl_form_title.Text = "Print Weaving Outward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR311":
                        lbl_form_title.Text = "Print Weaving Inward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR321":
                        lbl_form_title.Text = "Print Weaving Adjustment Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR401":
                        lbl_form_title.Text = "Print Washing Outward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR411":
                        lbl_form_title.Text = "Print Washing Inward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR501":
                        lbl_form_title.Text = "Print Tailoring Outward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR511":
                        lbl_form_title.Text = "Print Tailoring Outward Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR601":
                        lbl_form_title.Text = "Print Payment Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR602":
                        lbl_form_title.Text = "Print Receipt Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        break;
                    case "RPTR603":
                        double p_weaver_prev_week_weight_os = 0;
                        double p_weaver_curr_week_weight_os = 0;
                        double p_weaver_curr_week_weight_adj = 0;
                        p_weaver_prev_week_weight_os = PCDB.m_get_weaver_previous_week_weight_os(DateTime.Parse(PCPUB.m_record_date).ToString("yyyy-MM-dd"), PCPUB.m_record_id.ToString());
                        p_weaver_curr_week_weight_os = PCDB.m_get_weaver_current_week_weight_os(DateTime.Parse(PCPUB.m_record_date).ToString("yyyy-MM-dd"), PCPUB.m_record_id.ToString());
                        p_weaver_curr_week_weight_adj = PCDB.m_get_weaver_current_week_weight_adj(DateTime.Parse(PCPUB.m_record_date).ToString("yyyy-MM-dd"), PCPUB.m_record_id.ToString());                        
                        lbl_form_title.Text = "Print Payment Slip";
                        rd1.SetParameterValue("p_org_name", rep_org_name.ToString());
                        rd1.SetParameterValue("p_org_address", rep_org_address.ToString());
                        rd1.SetParameterValue("p_date", DateTime.Parse(PCPUB.m_record_date));
                        rd1.SetParameterValue("p_id", PCPUB.m_record_id);
                        rd1.SetParameterValue("p_weaver_prev_week_weight_os", p_weaver_prev_week_weight_os);
                        rd1.SetParameterValue("p_weaver_curr_week_weight_os", p_weaver_curr_week_weight_os);
                        rd1.SetParameterValue("p_weaver_curr_week_weight_adj", p_weaver_curr_week_weight_adj);
                        break;
                }
                dc = rd1.DataSourceConnections.Count;
                for (i = 0; i < dc; i++)
                {
                    rd1.DataSourceConnections[i].SetConnection(PCPUB.m_db_server.ToString(), PCPUB.m_db_name.ToString(), PCPUB.m_db_user.ToString(), PCPUB.m_db_password.ToString());
                }
                crv1.ReportSource = rd1;
                crv1.ShowFirstPage();
                UseWaitCursor = false;
            }
            catch (Exception e)
            {
                UseWaitCursor = false;
                PCMSG.ShowError(e);
            }
        }

        private void but_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void but_print_Click(object sender, EventArgs e)
        {
            crv1.PrintReport();
        }

        private void but_pdf_Click(object sender, EventArgs e)
        {
            pdf_report();
        }

        private void pdf_report()
        {
            int exportFormats = (int)(CrystalDecisions.Shared.ViewerExportFormats.PdfFormat);
            crv1.AllowedExportFormats = exportFormats;
            crv1.ExportReport();
        }

        private void zoom_report(int p_zoom_scale)
        {
            int i_zoom_scale;
            switch (p_zoom_scale)
            {
                case 2:
                    i_zoom_scale = 2;
                    break;
                case 3:
                    i_zoom_scale = 100;
                    break;
                default:
                    i_zoom_scale = 1;
                    break;
            }
            crv1.Zoom(i_zoom_scale);
        }

        private void but_zoom_Click(object sender, EventArgs e)
        {
            zoom_scale++;
            if (zoom_scale > 3)
                zoom_scale = 1;
            zoom_report(zoom_scale);
        }

        private void but_first_Click(object sender, EventArgs e)
        {
            crv1.ShowFirstPage();
        }

        private void but_previous_Click(object sender, EventArgs e)
        {
            crv1.ShowPreviousPage();
        }

        private void but_next_Click(object sender, EventArgs e)
        {
            crv1.ShowNextPage();
        }

        private void but_last_Click(object sender, EventArgs e)
        {
            crv1.ShowLastPage();
        }

        private void pnl_t4_Paint(object sender, PaintEventArgs e)
        {

        }

    }

}
